#include <iostream>
#include <cstring>
using namespace std;

const int N = 505, M = 1e5 + 5;
int dist[N], backup[N], n, m, k;
struct {
    int a, b, c;
} edge[M];
int idx;

int main()
{
    cin >> n >> m >> k;
    for(int i = 0; i < m; ++i) cin >> edge[i].a >> edge[i].b >> edge[i].c;
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;
    for(int i = 0; i < k; ++i)
    {
        memcpy(backup, dist, sizeof dist); // 存备份,避免单次遍历时,前面的影响后面的
        for(int j = 0; j < m; ++j)
            dist[edge[j].b] = min(dist[edge[j].b], backup[edge[j].a] + edge[j].c);
    }
    if(dist[n] > 0x3f3f3f3f / 2) cout << "impossible"; // 不能直接写等于,因为有可能会有点 用负权边 更新dist[n]的结果
    else cout << dist[n];
    return 0;
}